import os

from demo_app.blueprints import register_blueprints
from demo_app.commands import register_commands
from demo_app.settings import config
from demo_app.extensions import register_extensions


def init_app(app, config_name=None):
    """ app 初始化 """
    if config_name is None:
        config_name = os.getenv('FLASK_CONFIG', 'development')
    app.config.from_object(config[config_name])
    register_extensions(app)
    register_blueprints(app)
    register_commands(app)
    print("完成初始化APP:", app.config.get("APP_NAME"))
    return app
